local extension = Package("ldequips", Package.CardPack)
extension.extensionName = "brokenroyal"
extension.game_modes_whitelist = {"brokenroyal_mode"}

local ld = require "packages/brokenroyal/util"
local U = require "packages/utility/utility"

Fk:loadTranslationTable{
    ["ldequips"] = "裂鼎装备牌",
  }

local brokenroyal_targetmod = fk.CreateTargetModSkill{
  name = "#brokenroyal_targetmod",
  residue_func = function(self, player, skill, scope, card)
    if skill.trueName == "slash_skill" and scope == Player.HistoryPhase then
      if card.skillName == "bamboojavelin_skill&" then
        return 999
      end
    end
  end,
}

Fk:addSkill(brokenroyal_targetmod)

local sixdragon_skill = fk.CreateActiveSkill{
  name = "sixdragon_skill&",
  anim_type = "special",
  expand_pile = "#standby",
  prompt = "你可除外一张坐骑牌视为装备之",
  target_num = 0,
  card_num = 1,
  can_use = function(self, player)
    return not ld.hasPolicyorTrap(player, "eightdiagrams")
  end,
  card_filter = function(self, to_select, selected)
    return #selected == 0 and Fk:getCardById(to_select).sub_type == Card.SubtypeOffensiveRide
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    room:moveCardTo(effect.cards, Card.Processing, player, fk.ReasonJustMove, self.name)
    player:addToPile("sixdragon", effect.cards, true, "sixdragon")
  end,
}

local sixdragon = fk.CreateTreasure{
  name = "sixdragon",
  suit = Card.Spade,
  number = 1,
  equip_skill = sixdragon_skill,
  on_install = function(self, room, player)
    room:handleAddLoseSkills(player, "sixdragon_skill&", nil, false, true)
    local ld_equips = room:getBanner("@$equips") or {}
    local horses = table.filter(ld_equips, function(id) return Fk:getCardById(id).sub_type == Card.SubtypeOffensiveRide end)
    if #horses > 0 then
      local id = room:askForCardChosen(player, player, {
        card_data = {
          { "horses", horses }
        }
      }, self.name)
      if id ~= -1 then
        table.removeOne(ld_equips, id)
        table.shuffle(ld_equips)
        room:setBanner("@$equips", ld_equips)
        room:moveCardTo(id, Card.PlayerHand, player, fk.ReasonJustMove, self.name)
      end
    end
  end,
  on_uninstall = function(self, room, player)
    room:handleAddLoseSkills(player, "-sixdragon_skill&", nil, false, true)
    room:moveCardTo(player:getPile("sixdragon"), Card.DiscardPile, nil, fk.ReasonDiscard, self.name)
  end,
}

Fk:addSkill(sixdragon_skill)
extension:addCard(sixdragon)
  
Fk:loadTranslationTable{
    ["sixdragon"] = "六龙骖驾",
    ["sixdragon_skill&"] = "六龙骖驾",
    [":sixdragon"] = "<font color=\"#009E60\"><b>装备牌/宝物</b></font><br /><b>宝物技能</b>：此牌置入装备区时，你从锻造区获得一张坐骑牌；出牌阶段，你可除外一张坐骑牌视为装备之；此牌离开装备区时，你弃置所有除外的坐骑牌。",
}

local chain_mail_skill = fk.CreateTriggerSkill{
  name = "#chain_mail",
  --anim_type = "offensive",
  mute = true,
  frequency = Skill.Compulsory,
  events = {fk.TargetConfirmed},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self.name) and (data.card.name == "shot__slash" or data.card.trueName == "archery_attack")
    and ld.hasStandbyEquip(player, "chain_mail")
  end,
  on_use = function(self, event, target, player, data)
    player.room:notifySkillInvoked(player, "chain_mail", "defensive")
    table.insertIfNeed(data.nullifiedTargets, player.id)
  end,
}

local chain_mail = fk.CreateArmor{
  name = "chain_mail",
  suit = Card.Spade,
  number = 2,
}

Fk:addSkill(chain_mail_skill)
extension:addCard(chain_mail)
ld.addCardToStandby(chain_mail)

Fk:loadTranslationTable{
  ["chain_mail"] = "环锁铠",
  ["#chain_mail"] = "环锁铠",
  [":chain_mail"] = "<font color=\"#009E60\"><b>装备牌·备用/防具</b></font><br /><b>防具技能</b>：【射】和【箭雨】对你无效。",
}

local breastplate_skill = fk.CreateTriggerSkill{
  name = "#ld_breastplate",
  frequency = Skill.Compulsory,
  mute = true,
  events = {fk.DamageInflicted},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self.name) and ld.hasStandbyEquip(player, "ld__breastplate") and data.damage > 1
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    player.room:notifySkillInvoked(player, "ld__breastplate", "defensive")
    data.damage = 1
  end,
  --can_refresh
}

local breastplate = fk.CreateArmor{
  name = "ld__breastplate",
  suit = Card.Spade,
  number = 3,
}
  
Fk:addSkill(breastplate_skill)
extension:addCard(breastplate)
ld.addCardToStandby(breastplate)
  
Fk:loadTranslationTable{
    ["ld__breastplate"] = "护心镜",
    ["#ld_breastplate"] = "护心镜",
    [":ld__breastplate"] = "<font color=\"#009E60\"><b>装备牌·备用/防具</b></font><br /><b>防具技能</b>：当你受到大于1点的伤害时，将伤害减少至1点。",
}

local whitehorse_draw = fk.CreateTriggerSkill{
  name = "#whitehorse_draw",
  priority = 4,
  events = {fk.TurnEnd, fk.AskForCardUse},
  can_trigger = function(self, event, target, player, data)
    if event == fk.AskForCardUse then
      if player.phase ~= Player.NotActive or data.cardName ~= "plan" then return false end
    end
    return target == player and (player:hasSkill("#whitehorse_skill") or ld.hasStandbyEquip(player, "whitehorse")) and ld.Equipinvoked(player, "whitehorse")
  end,
  on_cost = function(self, event, target, player, data)
    if event == fk.TurnEnd then
      local card = player.room:askForCard(player, 1, 1, false, self.name, true, ".", "#whitehorse_ask")
      if #card > 0 then
        self.cost_data = card
        return true
      end
    else
      return player.room:askForSkillInvoke(player, self.name, nil, "#whitehorse-invoke")
    end
  end,
  on_use = function(self, event, target, player, data)
    if event == fk.TurnEnd then
      player.room:moveCardTo(self.cost_data, Card.DiscardPile, nil, fk.ReasonDiscard, self.name, "", true, player.id)
      ld.addinstruction(player, 1)
    else
      local card
      if player:getEquipment(Card.SubtypeOffensiveRide) and Fk:getCardById(player:getEquipment(Card.SubtypeOffensiveRide)).name == "whitehorse" then
        card = player:getEquipment(Card.SubtypeOffensiveRide)
      elseif #table.filter(player:getPile("sixdragon"), function(id) return Fk:getCardById(id).name == "whitehorse" end) > 0 then
        card = table.filter(player:getPile("sixdragon"), function(id) return Fk:getCardById(id).name == "whitehorse" end)[1]
      end
      if card ~= -1 then
        player.room:moveCardTo(card, Card.DiscardPile, nil, fk.ReasonDiscard, self.name)
      end
      ld.addinstruction(player, 3)
    end
  end,
}

local whitehorse_skill = fk.CreateTriggerSkill{
  name = "#whitehorse_skill",
  attached_equip = "whitehorse",
}

local whitehorse = fk.CreateOffensiveRide{
  name = "whitehorse",
  suit = Card.Spade,
  number = 4,
  equip_skill = whitehorse_skill,
}

Fk:addSkill(whitehorse_skill)
Fk:addSkill(whitehorse_draw)
extension:addCard(whitehorse)
  
Fk:loadTranslationTable{
    ["whitehorse"] = "义从",
    ["#whitehorse_skill"] = "义从",
    ["#whitehorse_draw"] = "义从",
    ["#whitehorse_ask"] = "义从：你可以弃置一张手牌加1点指令",
    ["#whitehorse-invoke"] = "你可以弃置【义从】，加3点指令",
    [":whitehorse"] = "<font color=\"#009E60\"><b>装备牌/坐骑</b></font><br /><b>技能</b>：回合结束时，你可弃置一张手牌加1点指令；你的回合外，当你需要使用【计】时，你可弃置此牌加3点指令。",
}

local chariot_slash = fk.CreateTriggerSkill{
  name = "#chariot_slash",
  priority = 4,
  events = {fk.TargetSpecified},
  can_trigger = function(self, event, target, player, data)
    return target == player and data.card and data.card.name == "br__slash" and
    (player:hasSkill("#chariot_skill") or ld.hasStandbyEquip(player, "chariot")) and ld.Equipinvoked(player, "chariot")
  end,
  on_use = function(self, event, target, player, data)
    player:drawCards(2, "chariot")
    local card
    if player:getEquipment(Card.SubtypeOffensiveRide) and Fk:getCardById(player:getEquipment(Card.SubtypeOffensiveRide)).name == "chariot" then
      card = player:getEquipment(Card.SubtypeOffensiveRide)
    elseif #table.filter(player:getPile("sixdragon"), function(id) return Fk:getCardById(id).name == "chariot" end) > 0 then
      card = table.filter(player:getPile("sixdragon"), function(id) return Fk:getCardById(id).name == "chariot" end)[1]
    end
    if card ~= -1 then
      player.room:moveCardTo(card, Card.DiscardPile, nil, fk.ReasonDiscard, self.name)
    end
    data.disresponsive = true
  end
}

local chariot_skill = fk.CreateTriggerSkill{
  name = "#chariot_skill",
  attached_equip = "chariot",
}

local chariot = fk.CreateOffensiveRide{
  name = "chariot",
  suit = Card.Spade,
  number = 5,
  equip_skill = chariot_skill,
}

Fk:addSkill(chariot_skill)
Fk:addSkill(chariot_slash)
extension:addCard(chariot)
  
Fk:loadTranslationTable{
  ["chariot"] = "战车",
  ["#chariot_skill"] = "战车",
  ["#chariot_slash"] = "战车",
  [":chariot"] = "<font color=\"#009E60\"><b>装备牌/坐骑</b></font><br /><b>技能</b>：当你使用【杀】指定目标后，你可摸两张牌，然后你弃置此牌令此【杀】无法被响应。",
}

local warelephant_throw = fk.CreateTriggerSkill{
  name = "#warelephant_throw",
  mute = true,
  events = {fk.Damaged},
  can_trigger = function(self, event, target, player, data)
    return target == player and (ld.hasStandbyEquip(player, "warelephant") or 
    (player:getEquipment(Card.SubtypeOffensiveRide) and Fk:getCardById(player:getEquipment(Card.SubtypeOffensiveRide)).name == "warelephant"))
    and data.card and data.card.name == "shot__slash" and ld.Equipinvoked(player, "warelephant")
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    local card = {}
    if player:getEquipment(Card.SubtypeOffensiveRide) and Fk:getCardById(player:getEquipment(Card.SubtypeOffensiveRide)).name == "warelephant" then
      card = {player:getEquipment(Card.SubtypeOffensiveRide)}
    elseif #table.filter(player:getPile("sixdragon"), function(id) return Fk:getCardById(id).name == "warelephant" end) > 0 then
      card = table.filter(player:getPile("sixdragon"), function(id) return Fk:getCardById(id).name == "warelephant" end)
    end
    if #card > 0 then
      player.room:moveCardTo(card[1], Card.DiscardPile, nil, fk.ReasonDiscard, self.name)
    end
  end,
  --can_refresh
}

local warelephant_skill = fk.CreateProhibitSkill{
  name = "#warelephant_skill",
  attached_equip = "warelephant",
  is_prohibited = function(self, from, to, card)
    if to:hasSkill(self.name) and not ld.hasPolicyorTrap(to, "eightdiagrams") then
      return card.sub_type == Card.SubtypeOffensiveRide
    end
  end,
}

local warelephant = fk.CreateOffensiveRide{
  name = "warelephant",
  suit = Card.Spade,
  number = 6,
  equip_skill = warelephant_skill,
  on_install = function(self, room, player)
    room:handleAddLoseSkills(player, "#warelephant_skill", nil, false, true)
    if ld.Equipinvoked(player, "warelephant") then
      ld.addinstruction(player, 1)
      room:recover({
        who = player,
        num = 1,
        recoverBy = player,
        skillName = self.name
      })
    end
  end,
  on_uninstall = function(self, room, player)
    room:handleAddLoseSkills(player, "-#warelephant_skill", nil, false, true)
  end,
}

Fk:addSkill(warelephant_throw)
Fk:addSkill(warelephant_skill)
extension:addCard(warelephant)
  
Fk:loadTranslationTable{
  ["warelephant"] = "战象",
  [":warelephant"] = "<font color=\"#009E60\"><b>装备牌/坐骑</b></font><br /><b>技能</b>：此牌置入坐骑栏后，你恢复1点国力并加1点指令。<br />若此牌在坐骑栏，你不能使用坐骑牌；你受到【射】造成的伤害后弃置此牌。",
}

local mace_skill = fk.CreateTriggerSkill{
  name = "#mace",
  frequency = Skill.Compulsory,
  attached_equip = "mace",
  events = {fk.DamageCaused},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self.name) and ld.Equipinvoked(player, "mace") and
    data.card and data.card.name == "br__slash" and data.card.color == Card.Black and data.to:getHandcardNum() < 2
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    data.damage = data.damage + 1
  end,
}

local mace = fk.CreateWeapon{
  name = "mace",
  suit = Card.Spade,
  number = 7,
  equip_skill = mace_skill,
}
  
Fk:addSkill(mace_skill)
extension:addCard(mace)
  
Fk:loadTranslationTable{
  ["mace"] = "狼牙棒",
  ["#mace"] = "狼牙棒",
  [":mace"] = "<font color=\"#009E60\"><b>装备牌/武器</b></font><br /><b>武器技能</b>：当你使用黑色【杀】造成伤害时：若目标手牌少于两张，此伤害+1。",
}

local poison_tube_skill = fk.CreateTriggerSkill{
  name = "#poison_tube",
  frequency = Skill.Compulsory,
  attached_equip = "poison_tube",
  events = {fk.Damage},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self.name) and ld.Equipinvoked(player, "poison_tube") and
    data.card and data.card.name == "shot__slash"
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    player.room:addPlayerMark(data.to, "@@poison")
  end,
}

local poison_tube = fk.CreateWeapon{
  name = "poison_tube",
  suit = Card.Spade,
  number = 8,
  equip_skill = poison_tube_skill,
}

local poison_buff = fk.CreateTriggerSkill{
  name = "#poison_buff",
  mute = true,
  global = true,
  events = {fk.PreHpRecover},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:getMark("@@poison") > 0 
  end,
  on_cost = Util.TrueFunc,  
  on_use = function(self, event, target, player, data)
    player.room:sendLog{
      type = "#poison_buff",
      from = player.id,
    }
    return true
  end,
  refresh_events = {fk.AfterTurnEnd},
  can_refresh = function(self, event, target, player, data)
    return target == player and (player:getMark("@@poison") > 0 or player:getMark("@@dizziness") > 0)
  end,
  on_refresh = function(self, event, target, player, data)
    player.room:setPlayerMark(player, "@@poison", 0)
    player.room:setPlayerMark(player, "@@dizziness", 0)
  end,
}
  
Fk:addSkill(poison_tube_skill)
Fk:addSkill(poison_buff)
extension:addCard(poison_tube)
  
Fk:loadTranslationTable{
  ["poison_tube"] = "毒吹筒",
  ["#poison_tube"] = "毒吹筒",
  [":poison_tube"] = "<font color=\"#009E60\"><b>装备牌/武器</b></font><br /><b>武器技能</b>：你使用【射】造成伤害后，目标下回合不能回复国力。",
  ["@@poison"] = "<font color=\"#CF9FFF\"><b>中毒</b></font>",
  ["#poison_buff"] = "%from 处于<font color=\"#CF9FFF\"><b>中毒</b></font>状态，无法回复国力",
}

local poison_dagger_skill = fk.CreateTriggerSkill{
  name = "#poison_dagger",
  attached_equip = "poison_dagger",
  events = {fk.DamageCaused},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self.name) and ld.Equipinvoked(player, "poison_dagger") and
    data.card and data.card.name == "br__slash"
  end,
  on_use = function(self, event, target, player, data)
    local judge = {
      who = player,
      reason = "poison_dagger",
      pattern = ".|.|spade,club",
    }
    player.room:judge(judge)
    local result = judge.card
    if result.color == Card.Black then
      data.damage = data.damage + 1
    end
  end,
}

local poison_dagger = fk.CreateWeapon{
  name = "poison_dagger",
  suit = Card.Spade,
  number = 9,
  equip_skill = poison_dagger_skill,
}

Fk:addSkill(poison_dagger_skill)
extension:addCard(poison_dagger)
  
Fk:loadTranslationTable{
  ["poison_dagger"] = "毒匕首",
  ["#poison_dagger"] = "毒匕首",
  [":poison_dagger"] = "<font color=\"#009E60\"><b>装备牌/武器</b></font><br /><b>武器技能</b>：当你使用【杀】造成伤害时：你可判定，若为黑色则伤害+1。",
}

local ringblade_skill = fk.CreateTriggerSkill{
  name = "#ringblade",
  attached_equip = "ringblade",
  events = {fk.CardEffectCancelledOut},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self.name) and data.card.name == "br__slash" and ld.Equipinvoked(player, "ringblade")
    and not player.room:getPlayerById(data.to):isKongcheng()
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local target = room:getPlayerById(data.to)
    local cid = room:askForCardChosen(player, target, "h", self.name)
    room:throwCard(cid, self.name, target)
    local judge = {
      who = player,
      reason = "ringblade",
      pattern = ".|.|spade",
    }
    player.room:judge(judge)
    local result = judge.card
    if result.suit == Card.Spade then
      room:damage({
        from = player,
        to = target,
        damage = 1,
        damageType = fk.NormalDamage,
        skillName = self.name,
      })
    end
  end,
}

local ringblade = fk.CreateWeapon{
  name = "ringblade",
  suit = Card.Spade,
  number = 10,
  equip_skill = ringblade_skill,
}

Fk:addSkill(ringblade_skill)
extension:addCard(ringblade)
  
Fk:loadTranslationTable{
  ["ringblade"] = "环扣刀",
  ["#ringblade"] = "环扣刀",
  [":ringblade"] = "<font color=\"#009E60\"><b>装备牌/武器</b></font><br /><b>武器技能</b>：当你使用【杀】被抵消后，你可弃置对方一张手牌，然后你判定，若为黑桃，则你对其造成1点伤害。",
}

local pumpkin_hummer_skill = fk.CreateTriggerSkill{
  name = "#pumpkin_hummer",
  frequency = Skill.Compulsory,
  attached_equip = "pumpkin_hummer",
  events = {fk.Damage},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self.name) and ld.Equipinvoked(player, "pumpkin_hummer") and
    data.card and data.card.name == "br__slash"
  end,
  on_cost = function(self, event, target, player, data)
    local card = player.room:askForCard(player, 1, 1, true, self.name, true, ".", "#pumpkin-throw::"..data.to.id)
    if #card > 0 then
      self.cost_data = card[1]
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    player.room:moveCardTo(self.cost_data, Card.DiscardPile, nil, fk.ReasonDiscard, self.name)
    player.room:addPlayerMark(data.to, "@@dizziness")
  end,
}

local pumpkin_hummer = fk.CreateWeapon{
  name = "pumpkin_hummer",
  suit = Card.Spade,
  number = 11,
  equip_skill = pumpkin_hummer_skill,
}

Fk:addSkill(pumpkin_hummer_skill)
extension:addCard(pumpkin_hummer)
  
Fk:loadTranslationTable{
  ["pumpkin_hummer"] = "南瓜锤",
  ["#pumpkin_hummer"] = "南瓜锤",
  [":pumpkin_hummer"] = "<font color=\"#009E60\"><b>装备牌/武器</b></font><br /><b>武器技能</b>：当你使用【杀】造成伤害后：你可弃置一张牌，令对方下个回合不能对你使用【杀】和【射】。",
  ["#pumpkin-throw"] = "南瓜锤：你可弃置一张牌，令%dest下个回合不能对你使用【杀】和【射】",
  ["#dizziness_buff"] = "晕眩",
  ["@@dizziness"] = "<font color=\"#FFD580\"><b>晕眩</b></font>",
}

local arbalest_skill = fk.CreateTriggerSkill{
  name = "#arbalest",
  attached_equip = "arbalest",
  events = {fk.EventPhaseEnd, fk.TargetSpecified},
  can_trigger = function(self, event, target, player, data)
    if target == player and player:hasSkill(self.name) and ld.Equipinvoked(player, "arbalest") then
      if event == fk.EventPhaseEnd then
        return player.phase == Player.Play
      elseif event == fk.TargetSpecified then
        return data.card.name == "shot__slash" and player:getMark("@@arbalest") > 0 and player:getMark("arbalest-turn") > 0
      end
    end
  end,
  on_cost = function(self, event, target, player, data)
    if event == fk.EventPhaseEnd then
      local cards = player.room:askForCard(player, 2, 2, false, self.name, true, ".", "#arbalest-discard")
      if #cards > 0 then
        self.cost_data = cards
        return true
      end
    else
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.EventPhaseEnd then
      room:moveCardTo(self.cost_data, Card.DiscardPile, nil, fk.ReasonDiscard, self.name)
      room:addPlayerMark(player, "@@arbalest")
    elseif event == fk.TargetSpecified then
      room:setPlayerMark(player, "arbalest-turn", 0)
      room:setPlayerMark(player, "@@arbalest", 0)
      data.additionalDamage = (data.additionalDamage or 0) + 1
      data.fixedResponseTimes = data.fixedResponseTimes or {}
      data.fixedResponseTimes["jink"] = 2
    end
  end,

  refresh_events = {fk.TurnStart, fk.TurnEnd},
  can_refresh = function(self, event, target, player, data)
    if event == fk.TurnStart then
      return target == player and player:getMark("@@arbalest") > 0
    elseif event == fk.TurnEnd then
      return target == player and player:getMark("arbalest-turn") > 0
    end
  end,
  on_refresh = function(self, event, target, player, data)
    if event == fk.TurnStart then
      player.room:addPlayerMark(player, "arbalest-turn")
    elseif event == fk.TurnEnd then
      player.room:setPlayerMark(player, "@@arbalest", 0)
    end
  end,
}

local arbalest = fk.CreateWeapon{
  name = "arbalest",
  suit = Card.Spade,
  number = 12,
  equip_skill = arbalest_skill,
  on_install = function(self, room, player)
    room:handleAddLoseSkills(player, "#arbalest", nil, false, true)
  end,
  on_uninstall = function(self, room, player)
    room:handleAddLoseSkills(player, "-#arbalest", nil, false, true)
    room:setPlayerMark(player, "@@arbalest", 0)
  end,
}

Fk:addSkill(arbalest_skill)
extension:addCard(arbalest)
  
Fk:loadTranslationTable{
  ["arbalest"] = "角弩",
  ["#arbalest"] = "角弩",
  ["@@arbalest"] = "<font color=\"#E30B5C\">角弩蓄力</font>",
  ["#arbalest-discard"] = "角弩：你可以弃置两张手牌",
  [":arbalest"] = "<font color=\"#009E60\"><b>装备牌/武器</b></font><br /><b>武器技能</b>：出牌阶段结束时，你可弃置两张手牌，下回合你使用第一张【射】伤害+1且须使用两张【防】抵消。",
}

local haidongqing_show = fk.CreateTriggerSkill{
  name = "#haidongqing_show",
  --anim_type = "offensive",
  events = {fk.TurnStart},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self.name) and ld.hasStandbyEquip(player, "haidongqing")
  end,
  on_cost = function(self, event, target, player, data)
    local targets = {}
    for _, p in ipairs(player.room:getOtherPlayers(player)) do
        table.insert(targets, p.id)
    end
    if #targets == 0 then return end
    local to = player.room:askForChoosePlayers(player, targets, 1, 1, "#haidongqing_target", self.name, true)
    if #to > 0 then
      self.cost_data = to[1]
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local to = room:getPlayerById(self.cost_data)
    to:showCards(to:getCardIds(Player.Hand))
  end,
  --can_refresh
}

local haidongqing = fk.CreateTreasure{
  name = "haidongqing",
  suit = Card.Spade,
  number = 13,
}
  
Fk:addSkill(haidongqing_show)
extension:addCard(haidongqing)
ld.addCardToStandby(haidongqing)
  
Fk:loadTranslationTable{
  ["haidongqing"] = "鹰王海东青",
  ["#haidongqing_show"] = "鹰王海东青",
  [":haidongqing"] = "<font color=\"#009E60\"><b>装备牌·备用/宝物</b></font><br /><b>宝物技能</b>：回合开始时，你可以观看对手的所有手牌。",
  ["#haidongqing_target"] = "鹰王海东青：你可令一名角色展示手牌",
}

local qingnangbook_skill = fk.CreateViewAsSkill{
  name = "qingnangbook_skill&",
  attached_equip = "qingnang_book",
  pattern = "br__analeptic",
  card_filter = function(self, to_select, selected)
    return #selected == 0 and Fk:getCardById(to_select).color == Card.Red
  end,
  view_as = function(self, cards)
    if #cards ~= 1 then
      return nil
    end
    local c = Fk:cloneCard("br__analeptic")
    c.skillName = self.name
    c:addSubcard(cards[1])
    return c
  end,
  before_use = function(self, player, use)
    if use.card.skillName == self.name then
      player.room:setPlayerMark(player, "qingnangbook", 2)
    end
  end,
  enabled_at_play = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryPhase) == 0 and player:getMark("qingnangbook") == 0
  end,
  enabled_at_response = function(self, player, response)
    return false
  end,
}

local qingnang_book = fk.CreateTreasure{
  name = "qingnang_book",
  suit = Card.Heart,
  number = 1,
  equip_skill = qingnangbook_skill,
}

Fk:addSkill(qingnangbook_skill)
extension:addCard(qingnang_book)

local qingnangbook_clear = fk.CreateTriggerSkill{
  name = "#qingnangbook_clear",
  global = true,
  refresh_events = {fk.AfterTurnEnd},
  can_refresh = function(self, event, target, player, data)
    return target == player and player:getMark("qingnangbook") > 0
  end,
  on_refresh = function(self, event, target, player, data)
    player.room:removePlayerMark(player, "qingnangbook")
  end,
}

Fk:addSkill(qingnangbook_clear)

Fk:loadTranslationTable{
  ["qingnang_book"] = "青囊残本",
  ["qingnangbook_skill&"] = "青囊残本",
  [":qingnang_book"] = "<font color=\"#009E60\"><b>装备牌/宝物</b></font><br /><b>宝物技能</b>：出牌阶段，你可以将一张红色牌当作【药】使用，然后你不能以此法使用【药】直到下回合结束。",
  [":qingnangbook_skill&"] = "出牌阶段，你可以将一张红色牌当作【药】使用，然后你不能以此法使用【药】直到下回合结束",
}

local beastshield_skill = fk.CreateTriggerSkill{
  name = "#beastshield_skill",
  attached_equip = "beastshield",
  frequency = Skill.Compulsory,
  events = {fk.TargetConfirmed},
  can_trigger = function(self, event, target, player, data)
    local user = player.room:getPlayerById(data.from)
    if user ~= player and target == player and player:hasSkill(self.name) and data.card.name == "br__slash" and ld.Equipinvoked(player, "beastshield") then
      return user:getEquipment(Card.SubtypeOffensiveRide) or #user:getPile("sixdragon") > 0 or ld.hasStandbyEquip(user, "camel")
    end
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    ld.addinstruction(player.room:getPlayerById(data.from), -1)
  end,
}

local beastshield = fk.CreateArmor{
  name = "beastshield",
  suit = Card.Heart,
  number = 2,
  equip_skill = beastshield_skill,
}

Fk:addSkill(beastshield_skill)
extension:addCard(beastshield)

Fk:loadTranslationTable{
  ["beastshield"] = "兽面盾",
  ["#beastshield_skill"] = "兽面盾",
  [":beastshield"] = "<font color=\"#009E60\"><b>装备牌/防具</b></font><br /><b>防具技能</b>：对手使用【杀】指定你为目标后，若其装备区有坐骑牌，其指令-1。",
}

local bladeshield_skill = fk.CreateTriggerSkill{
  name = "#bladeshield_skill",
  attached_equip = "bladeshield",
  anim_type = "masochism",
  events = {fk.Damaged},
  can_trigger = function(self, event, target, player, data)
    return target == player and data.from and data.from ~= player and player:hasSkill(self.name) and ld.Equipinvoked(player, "bladeshield")
    and data.card and data.card.name == "br__slash"
  end,
  on_cost = function(self, event, target, player, data)
    local card = player.room:askForCard(player, 1, 1, true, self.name, true, "jink", "#bladeshield::"..data.from.id)
    if #card > 0 then
      self.cost_data = card[1]
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:moveCardTo(self.cost_data, Card.DiscardPile, nil, fk.ReasonDiscard, self.name)
    room:damage({
      from = player,
      to = data.from,
      damage = 1,
      damageType = fk.NormalDamage,
      skillName = self.name,
    })
  end,
}

local bladeshield = fk.CreateArmor{
  name = "bladeshield",
  suit = Card.Heart,
  number = 3,
  equip_skill = bladeshield_skill,
}

Fk:addSkill(bladeshield_skill)
extension:addCard(bladeshield)

Fk:loadTranslationTable{
  ["bladeshield"] = "刃盾",
  ["#bladeshield_skill"] = "刃盾",
  ["#bladeshield"] = "刃盾：你可以弃置一张【防】，对%dest造成1点伤害",
  [":bladeshield"] = "<font color=\"#009E60\"><b>装备牌/防具</b></font><br /><b>防具技能</b>：对手使用【杀】对你造成伤害后，你可以弃置一张【防】，然后对其造成1点伤害。",
}

local monster_skill = fk.CreateTriggerSkill{  --需要一个空技能以判断equip_skill是否无效
  name = "#monster_skill",
  attached_equip = "monster",
}

local monster = fk.CreateOffensiveRide{
  name = "monster",
  suit = Card.Heart,
  number = 4,
  equip_skill = monster_skill,
  on_install = function(self, room, player)
    if ld.Equipinvoked(player, "monster") then
      ld.searchForTrickCard(self, room, player, "br__fire_attack")
      room:setPlayerMark(player:getNextAlive(), "@@horse_invalid", 1)
    end
  end,
  on_uninstall = function(self, room, player)
    room:setPlayerMark(player:getNextAlive(), "@@horse_invalid", 0)
  end,
}

Fk:addSkill(monster_skill)
extension:addCard(monster)
  
Fk:loadTranslationTable{
  ["monster"] = "怪兽",
  ["@@horse_invalid"] = "<font color=\"#FA8072\">坐骑无效</font>",
  [":monster"] = "<font color=\"#009E60\"><b>装备牌/坐骑</b></font><br /><b>技能</b>：此牌置入坐骑栏后，你从计谋区获得一张【火攻】；然后对手的坐骑牌无效直到此牌离开坐骑栏。<br /><font color=\"#630330\">（注：按此描述，此牌通过六龙骖驾除外没有效果）</font>",
}

local ferghana_damage = fk.CreateTriggerSkill{
  name = "#ferghana_damage",
  events = {fk.DamageCaused},
  can_trigger = function(self, event, target, player, data)
    return target == player and data.card and data.card.name == "br__slash" and (player:hasSkill("#ferghana_skill") or ld.hasStandbyEquip(player, "ferghana"))
    and data.card.color == Card.Red and (player:getEquipment(Card.SubtypeWeapon) or data.card.suit == Card.Heart) and ld.Equipinvoked(player, "ferghana")
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    data.damage = data.damage + 1
  end,
}

local ferghana_skill = fk.CreateTriggerSkill{
  name = "#ferghana_skill",
  attached_equip = "ferghana",
}

local ferghana = fk.CreateOffensiveRide{
  name = "ferghana",
  suit = Card.Heart,
  number = 5,
  equip_skill = ferghana_skill,
}

Fk:addSkill(ferghana_skill)
Fk:addSkill(ferghana_damage)
extension:addCard(ferghana)
  
Fk:loadTranslationTable{
  ["ferghana"] = "汗血",
  ["#ferghana_skill"] = "汗血",
  ["#ferghana_damage"] = "汗血",
  [":ferghana"] = "<font color=\"#009E60\"><b>装备牌/坐骑</b></font><br /><b>技能</b>：你使用<font color=\"#FF4433\">红桃</font>【杀】造成的伤害+1，若你装备区有武器牌，则“<font color=\"#FF4433\">红桃</font>”改为“<font color=\"#DC143C\">红色</font>”。",
}

local bronco_damage = fk.CreateTriggerSkill{
  name = "#bronco_damage",
  events = {fk.CardUseFinished},
  can_trigger = function(self, event, target, player, data)
    return target == player and data.card and data.card.name == "br__slash" and
     (player:hasSkill("#bronco_skill") or ld.hasStandbyEquip(player, "bronco")) and ld.Equipinvoked(player, "bronco")
  end,
  on_use = function(self, event, target, player, data)
    local judge = {
      who = player,
      reason = "bronco",
      pattern = ".|.|heart,diamond",
    }
    player.room:judge(judge)
    local result = judge.card
    if result.color == Card.Red and (data.damageDealt or result.suit == Card.Heart) then
      ld.addinstruction(player, 1)
    end
  end,
}

local bronco_skill = fk.CreateTriggerSkill{
  name = "#bronco_skill",
  attached_equip = "bronco",
}

local bronco = fk.CreateOffensiveRide{
  name = "bronco",
  suit = Card.Heart,
  number = 6,
  equip_skill = bronco_skill,
}

Fk:addSkill(bronco_skill)
Fk:addSkill(bronco_damage)
extension:addCard(bronco)
  
Fk:loadTranslationTable{
  ["bronco"] = "烈马",
  ["#bronco_skill"] = "烈马",
  ["#bronco_damage"] = "烈马",
  [":bronco"] = "<font color=\"#009E60\"><b>装备牌/坐骑</b></font><br /><b>技能</b>：当你使用【杀】结算后，你可判定，若为<font color=\"#FF4433\">红桃</font>，你指令+1，若此【杀】造成伤害，则“<font color=\"#FF4433\">红桃</font>”改为“<font color=\"#DC143C\">红色</font>”。",
}

local circle_blade_skill = fk.CreateTriggerSkill{
  name = "#circle_blade",
  attached_equip = "circle_blade",
  events = {fk.DamageCaused},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self.name) and ld.Equipinvoked(player, "circle_blade") and
    data.card and data.card.name == "br__slash" and data.card.color == Card.Black and player:getMark("instruction") > 0
  end,
  on_use = function(self, event, target, player, data)
    ld.addinstruction(player, -1)
    data.damage = data.damage + 1
  end,
}

local circle_blade = fk.CreateWeapon{
  name = "circle_blade",
  suit = Card.Heart,
  number = 7,
  equip_skill = circle_blade_skill,
}

  
Fk:addSkill(circle_blade_skill)
extension:addCard(circle_blade)
  
Fk:loadTranslationTable{
  ["circle_blade"] = "环首刀",
  ["#circle_blade"] = "环首刀",
  [":circle_blade"] = "<font color=\"#009E60\"><b>装备牌/武器</b></font><br /><b>武器技能</b>：当你使用黑色【杀】造成伤害时，你可消耗1点指令使伤害+1。",
}

local exquisite_bow_skill = fk.CreateTriggerSkill{
  name = "#exquisite_bow",
  attached_equip = "exquisite_bow",
  events = {fk.TargetSpecified},
  can_trigger = function(self, event, target, player, data)
    if target == player and player:hasSkill(self.name) and data.tos and data.firstTarget and data.card.name == "shot__slash" and ld.Equipinvoked(player, "exquisite_bow") then
      local to = player.room:getPlayerById(data.to)
      return to:getHandcardNum() > 0 or to:getEquipment(Card.SubtypeOffensiveRide) or 
      #table.filter(to:getPile("#standby"), function(id) return Fk:getCardById(id).sub_type == Card.SubtypeOffensiveRide end) > 0 or
      #table.filter(to:getPile("sixdragon"), function(id) return Fk:getCardById(id).sub_type == Card.SubtypeOffensiveRide end) > 0
    end
  end,
  on_use = function(self, event, target, player, data)
    local to = player.room:getPlayerById(data.to)
    local cards = to:getCardIds(Player.Hand)
    if not to:isKongcheng() then
      cards = {}
      for i = 1, #to:getCardIds(Player.Hand), 1 do
        table.insert(cards, -1)
      end
    end
    local to_discard = {}
    if #cards ~= 0 then table.insertIfNeed(to_discard, {"$Hand", cards}) end
    if to:getEquipment(Card.SubtypeOffensiveRide) then table.insertIfNeed(to_discard, {"$Equip", {to:getEquipment(Card.SubtypeOffensiveRide)}}) end
    if #table.filter(to:getPile("#standby"), function(cid) return Fk:getCardById(cid).sub_type == Card.SubtypeOffensiveRide end) > 0 then
      table.insertIfNeed(to_discard, {"#standby", table.filter(to:getPile("#standby"), function(cid) return Fk:getCardById(cid).sub_type == Card.SubtypeOffensiveRide end)})
    end
    if #table.filter(to:getPile("sixdragon"), function(cid) return Fk:getCardById(cid).sub_type == Card.SubtypeOffensiveRide end) > 0 then
      table.insertIfNeed(to_discard, {"sixdragon", table.filter(to:getPile("sixdragon"), function(cid) return Fk:getCardById(cid).sub_type == Card.SubtypeOffensiveRide end)})
    end
    if #to_discard == 0 then return nil end
    local id = player.room:askForCardChosen(player, to, {card_data = to_discard}, self.name)
    if id ~= -1 then
      player.room:moveCardTo(id, Card.DiscardPile, nil, fk.ReasonDiscard, self.name, "", true, player.id)
    end
  end,
}

local exquisite_bow = fk.CreateWeapon{
  name = "exquisite_bow",
  suit = Card.Heart,
  number = 8,
  equip_skill = exquisite_bow_skill,
}
  
Fk:addSkill(exquisite_bow_skill)
extension:addCard(exquisite_bow)
  
Fk:loadTranslationTable{
  ["exquisite_bow"] = "雕弓",
  ["#exquisite_bow"] = "雕弓",
  [":exquisite_bow"] = "<font color=\"#009E60\"><b>装备牌/武器</b></font><br /><b>武器技能</b>：当你使用【射】指定目标后，你可以弃置其一张手牌或装备区的坐骑牌",
}

local bamboojavelin_skill = fk.CreateViewAsSkill{
  name = "bamboojavelin_skill&",
  --attached_equip = "bamboojavelin",
  pattern = "shot__slash",
  expand_pile = "#standby",
  card_filter = function(self, to_select, selected)
    return #selected == 0 and Self:getPileNameOfId(to_select) == "#standby" and Fk:getCardById(to_select).name == "bamboojavelin"
  end,
  view_as = function(self, cards)
    if #cards ~= 1 then
      return nil
    end
    local c = Fk:cloneCard("shot__slash")
    c.skillName = self.name
    c:addSubcard(cards[1])
    return c
  end,
}

local bamboojavelin_slash = fk.CreateTriggerSkill{
  name = "#bamboojavelin_slash",
  anim_type = "offensive",
  mute = true,
  priority = 4,
  events = {fk.CardUseFinished},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self.name) and data.card.name == "shot__slash" and
    data.card.skillName == "bamboojavelin_skill&" and player.room:getCardArea(data.card) == Card.Processing and data.damageDealt
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local to = room:getPlayerById(TargetGroup:getRealTargets(data.tos)[1])
    room:moveCardTo(data.card, Card.PlayerHand, to, fk.ReasonJustMove, self.name, "", true)
  end,
}

local bamboojavelin = fk.CreateWeapon{
  name = "bamboojavelin",
  suit = Card.Heart,
  number = 9,
}
  
Fk:addSkill(bamboojavelin_skill)
Fk:addSkill(bamboojavelin_slash)
extension:addCard(bamboojavelin)
ld.addCardToStandby(bamboojavelin)

Fk:loadTranslationTable{
  ["bamboojavelin"] = "山越飞竹",
  ["bamboojavelin_skill&"] = "山越飞竹",
  ["#bamboojavelin_slash"] = "山越飞竹",
  [":bamboojavelin"] = "<font color=\"#009E60\"><b>装备牌·备用/武器</b></font><br /><b>武器技能</b>：你可将此牌当作不消耗指令且无次数限制的【射】使用，若造成伤害，对手获得此牌。",
  [":bamboojavelin_skill&"] = "你可以将此牌当作不消耗指令且无次数限制的【射】使用，若造成伤害，对手获得此牌。",
}

local heroineblade_skill = fk.CreateTriggerSkill{
  name = "#heroineblade",
  attached_equip = "heroineblade",
  events = {fk.TargetSpecified},
  can_trigger = function(self, event, target, player, data)
    if target == player and player:hasSkill(self.name) and data.tos and data.firstTarget and data.card.name == "br__slash" then
      local to = player.room:getPlayerById(data.to)
      return to:getMark("instruction") > player:getMark("instruction") and ld.Equipinvoked(player, "heroineblade")
    end
  end,
  on_use = function(self, event, target, player, data)
    local to = player.room:getPlayerById(data.to)
    if to:isNude() then
      player:drawCards(1, self.name)
    else
      local result = player.room:askForDiscard(to, 1, 1, true, self.name, true, ".", "heroineblade-invoke::"..player.id)
      if #result == 0 then
        player:drawCards(1, self.name)
      end
    end
  end,
}

local heroineblade = fk.CreateWeapon{
  name = "heroineblade",
  suit = Card.Heart,
  number = 10,
  equip_skill = heroineblade_skill,
}

Fk:addSkill(heroineblade_skill)
extension:addCard(heroineblade)
  
Fk:loadTranslationTable{
  ["heroineblade"] = "巾帼刀",
  ["#heroineblade"] = "巾帼刀",
  [":heroineblade"] = "<font color=\"#009E60\"><b>装备牌/武器</b></font><br /><b>武器技能</b>：当你使用【杀】指定目标后，若其国力多于你，你可令其选择弃置一张牌或令你摸一张牌。",
  ["heroineblade-invoke"] = "巾帼刀：请弃置一张牌，否则%dest摸一张牌",
}

Fk:addPoxiMethod{
  name = "guardianarrow",
  card_filter = Util.TrueFunc,
  feasible = function(selected, data)
    return #selected == 4
  end,
  prompt = "戎边飞镝：你可以弃置四张方案区外的牌"
}

local guardianarrow_skill = fk.CreateTriggerSkill{
  name = "#guardianarrow",
  attached_equip = "guardianarrow",
  events = {fk.TargetSpecified},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self.name) and data.tos and data.firstTarget and data.card.name == "shot__slash"
    and ld.Equipinvoked(player, "guardianarrow")
  end,
  on_cost = function(self, event, target, player, data)
    local n = #player:getCardIds("he") + #player:getPile("#standby") + #player:getPile("sixdragon")
    n = math.min(n, 4)
    if n >= 4 then
      local to_discard = {}
      if #player:getCardIds{Player.Hand} ~= 0 then table.insertIfNeed(to_discard, {"$Hand", player:getCardIds{Player.Hand}}) end
      if #player:getCardIds{Player.Equip} ~= 0 then table.insertIfNeed(to_discard, {"$Equip", player:getCardIds{Player.Equip}}) end
      if #player:getPile("#standby") ~= 0 then table.insertIfNeed(to_discard, {"#standby", player:getPile("#standby")}) end
      if #player:getPile("sixdragon") ~= 0 then table.insertIfNeed(to_discard, {"sixdragon", player:getPile("sixdragon")}) end
      local cards = player.room:askForPoxi(player, "guardianarrow", to_discard)
      if #cards > 0 then
        self.cost_data = cards
        return true
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    player.room:moveCardTo(self.cost_data, Card.DiscardPile, nil, fk.ReasonDiscard, self.name)
    data.additionalDamage = (data.additionalDamage or 0) + 2
  end,
}

local guardianarrow = fk.CreateWeapon{
  name = "guardianarrow",
  suit = Card.Heart,
  number = 11,
  equip_skill = guardianarrow_skill,
}

Fk:addSkill(guardianarrow_skill)
extension:addCard(guardianarrow)
  
Fk:loadTranslationTable{
  ["guardianarrow"] = "戎边飞镝",
  ["#guardianarrow"] = "戎边飞镝",
  [":guardianarrow"] = "<font color=\"#009E60\"><b>装备牌/武器</b></font><br /><b>武器技能</b>：当你使用【射】指定目标后，你可弃置四张方案区外的牌（可包括此牌），则此【射】造成的伤害+2。",
}

local superdiagram_skill = fk.CreateTriggerSkill{
  name = "#superdiagram",
  attached_equip = super_diagram,
  events = {fk.AskForCardUse},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self.name) and data.cardName == "rumble" and player:usedSkillTimes(self.name) == 0
    and ld.Equipinvoked(player, "superdiagram")
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local judgeData = {
      who = player,
      reason = "super_diagram",
      pattern = ".|1~8",
    }
    room:judge(judgeData)
    if judgeData.card.number <= 8 then
      data.result = {
        from = player.id,
        card = Fk:cloneCard('rumble'),
      }
      data.result.card.skillName = "super_diagram"
      if data.eventData then
        data.result.toCard = data.eventData.toCard
        data.result.responseToEvent = data.eventData.responseToEvent
      end
      return true
    end
  end,
}

local super_diagram = fk.CreateTreasure{
  name = "super_diagram",
  suit = Card.Heart,
  number = 12,
  equip_skill = superdiagram_skill,
}

Fk:addSkill(superdiagram_skill)
extension:addCard(super_diagram)

Fk:loadTranslationTable{
  ["super_diagram"] = "石兵八卦阵",
  ["#superdiagram"] = "石兵八卦阵",
  [":super_diagram"] = "<font color=\"#009E60\"><b>装备牌/宝物</b></font><br /><b>宝物技能</b>：每回合限一次，当你需要使用【破】时，若你有至少1点指令，你可以判定，若点数不大于８，则视为你使用之。",
}

local sundial_skill = fk.CreateTriggerSkill{
  name = "#sundial_skill",
  attached_equip = sundial,
  events = {fk.TurnEnd},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self.name) and player:getMark("instruction") >= 5 and ld.Equipinvoked(player, "sundial")
  end,
  on_use = function(self, event, target, player, data)
    if player:getEquipment(Card.SubtypeTreasure) and Fk:getCardById(player:getEquipment(Card.SubtypeTreasure)).name == "sundial" then
      player.room:moveCardTo(player:getEquipment(Card.SubtypeTreasure), Card.Void, nil, fk.ReasonJustMove, self.name, "", true, player.id)
      ld.addinstruction(player, -5)
      player:gainAnExtraTurn()
    end
  end,
}

local sundial = fk.CreateTreasure{
  name = "sundial",
  suit = Card.Heart,
  number = 13,
  equip_skill = sundial_skill,
}

Fk:addSkill(sundial_skill)
extension:addCard(sundial)

Fk:loadTranslationTable{
  ["sundial"] = "逆流日晷",
  ["#sundial_skill"] = "逆流日晷",
  [":sundial"] = "<font color=\"#009E60\"><b>装备牌/宝物</b></font><br /><b>宝物技能</b>：回合结束时，你可将此牌移出游戏并消耗5点指令，获得一个额外的回合。",
}


local wooden_ox_active = fk.CreateActiveSkill{
  name = "wooden_ox_active&",
  prompt = "你可以摸两张牌，然后弃置两张牌",
  attached_equip = "br__wooden_ox",
  target_num = 0,
  card_num = 0,
  card_filter = Util.FalseFunc,
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryPhase) == 0 and not ld.hasPolicyorTrap(player, "eightdiagrams")
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    player:drawCards(2, "br__wooden_ox")
    room:askForDiscard(player, 2, 2, true, self.name, false)
  end,
}

local wooden_ox_skill = fk.CreateTriggerSkill{
  name = "#wooden_ox_skill",
  attached_equip = "br__wooden_ox",
  mute = true,
  priority = 4,
  events = {fk.CardUseFinished},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self.name) and data.card.name == "br__grain" and not ld.hasPolicyorTrap(player, "eightdiagrams")
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    player:drawCards(2, "br__wooden_ox")
  end,
}

local wooden_ox = fk.CreateTreasure{
  name = "br__wooden_ox",
  suit = Card.Club,
  number = 1,
  equip_skill = wooden_ox_skill,
  on_install = function(self, room, player)
    room:handleAddLoseSkills(player, "#wooden_ox_skill|wooden_ox_active&", nil, false, true)
  end,
  on_uninstall = function(self, room, player)
    room:handleAddLoseSkills(player, "-#wooden_ox_skill|-wooden_ox_active&", nil, false, true)
  end,
}

Fk:addSkill(wooden_ox_active)
Fk:addSkill(wooden_ox_skill)
extension:addCard(wooden_ox)

Fk:loadTranslationTable{
  ["br__wooden_ox"] = "木牛流马",
  ["#wooden_ox_skill"] = "木牛流马",
  ["wooden_ox_active&"] = "木牛流马",
  [":br__wooden_ox"] = "<font color=\"#009E60\"><b>装备牌/宝物</b></font><br /><b>宝物技能</b>：你使用【粮】后摸两张牌；出牌阶段限一次，你可摸两张牌，然后弃置两张牌。",
}

local liangdangarmor_skill = fk.CreateTriggerSkill{
  name = "#liangdangarmor",
  frequency = Skill.Compulsory,
  attached_equip = "liangdangarmor",
  events = {fk.DamageInflicted},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self.name) and ld.Equipinvoked(player, "liangdangarmor") and
    data.from and data.from ~= player
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local armor = player:getEquipment(Card.SubtypeArmor)
    local ld_equips = room:getBanner("@$equips") or {}
    local armors = {}
    if #ld_equips > 0 then
      armors = table.filter(ld_equips, function(id) return Fk:getCardById(id).sub_type == Card.SubtypeArmor end)
    end
    room:moveCardTo(armor, Card.DiscardPile, nil, fk.ReasonDiscard, self.name)
    if player:getMark("instruction") > 0 and #armors > 0 and room:askForSkillInvoke(player, self.name, data, "#liangdangarmor_draw") then
      ld.addinstruction(player, -1)
      room.logic:trigger("fk.StartDiscover", player)
      local n = 3
      if player:getMark("extradiscover") > 0 then
        n = n + player:getMark("extradiscover")
        room:setPlayerMark(player, "extradiscover", 0)
      end
      local showcards = table.random(armors, n)
      local id = room:askForCardChosen(player, player, {
        card_data = {
          { "liangdangarmor", showcards }
        }
      }, self.name)
      table.removeOne(ld_equips, id)
      table.shuffle(ld_equips)
      room:setBanner("@$equips", ld_equips)
      room:moveCardTo(id, Card.PlayerHand, player, fk.ReasonJustMove, self.name)
    end
    return true
  end,
}

local liangdangarmor = fk.CreateArmor{
  name = "liangdangarmor",
  suit = Card.Club,
  number = 2,
  equip_skill = liangdangarmor_skill,
}
  
Fk:addSkill(liangdangarmor_skill)
extension:addCard(liangdangarmor)
  
Fk:loadTranslationTable{
  ["liangdangarmor"] = "两当铠",
  ["#liangdangarmor"] = "两当铠",
  [":liangdangarmor"] = "<font color=\"#009E60\"><b>装备牌/防具</b></font><br /><b>防具技能</b>：对手对你造成伤害时：你防止此次伤害并弃置此牌，然后你可消耗1点指令，发现一张其他防具牌。",
  ["#liangdangarmor_draw"] = "两当铠：你可以消耗1点指令，发现一张其他防具牌",
}

local niohShieldSkill = fk.CreateTriggerSkill{
  name = "#br__nioh_shield_skill",
  attached_equip = "nioh_shield",
  frequency = Skill.Compulsory,
  events = {fk.PreCardEffect},
  can_trigger = function(self, event, target, player, data)
    if player.id == data.to and player:hasSkill(self.name) and data.card.name == "br__slash" and ld.Equipinvoked(target, "br__nioh_shield") then
       return data.card.suit == Card.Club or (data.card.suit == Card.Spade and #player.room.logic:getEventsOfScope(GameEvent.ChangeHp, 1, function (e)
        local damage = e.data[5]
        if damage and player == damage.from and player ~= damage.to then
          return true
        end
      end, Player.HistoryGame) == 0)
    end
  end,
  on_use = Util.TrueFunc,
}

Fk:addSkill(niohShieldSkill)

local niohShield = fk.CreateArmor{
  name = "br__nioh_shield",
  suit = Card.Club,
  number = 3,
  equip_skill = niohShieldSkill,
}

extension:addCards({
  niohShield,
})

Fk:loadTranslationTable{
  ["br__nioh_shield"] = "仁王盾",
  ["#br__nioh_shield_skill"] = "仁王盾",
  [":br__nioh_shield"] = "<font color=\"#009E60\"><b>装备牌/防具</b></font><br /><b>宝物技能</b>：梅花【杀】对你无效，若你没有对对手造成过伤害，则黑桃【杀】也对你无效。",
}

local nightcloth_skill = fk.CreateTriggerSkill{
  name = "#nightcloth_skill",
  attached_equip = "nightcloth",
  priority = 2,
  events = {fk.PreCardEffect},
  can_trigger = function(self, event, target, player, data)
    if data.from == player.id then return false end
    if data.card.type == Card.TypeTrick and data.card:getMark("@@policy") == 0 and data.card.suit ~= Card.Diamond then
      return player:hasSkill(self.name) and ld.Equipinvoked(player, "nightcloth")
    end
  end,
  on_use = function(self, event, target, player, data)
    local judge = {
      who = player,
      reason = "nightcloth",
      pattern = ".|.|black",
    }
    player.room:judge(judge)
    local result = judge.card
    if result.color == Card.Black then
      player.room:sendLog{
        type = "#nightcloth",
        from = player.id,
        arg = data.card:toLogString(),
        toast = true,
      }
      player.room:moveCardTo(player:getEquipment(Card.SubtypeArmor), Card.DiscardPile, nil, fk.ReasonDiscard, self.name)
      return true
    end
  end,
}

local nightcloth = fk.CreateArmor{
  name = "nightcloth",
  suit = Card.Club,
  number = 4,
  equip_skill = nightcloth_skill,
}

Fk:addSkill(nightcloth_skill)
extension:addCard(nightcloth)

Fk:loadTranslationTable{
  ["nightcloth"] = "夜行衣",
  ["#nightcloth_skill"] = "夜行衣",
  [":nightcloth"] = "<font color=\"#009E60\"><b>装备牌/防具</b></font><br /><b>防具技能</b>：对手使用没有“方针”标识且非方片计谋牌生效前，你可判定，若为黑色，则你弃置【夜行衣】，令之无效。</b>",
  ["#nightcloth"] = "%arg 被无效",
}

local camel_trigger = fk.CreateTriggerSkill{
  name = "#camel_trigger",
  refresh_events = {fk.EventPhaseStart},
  can_refresh = function(self, event, target, player, data)
    if target == player and ld.hasStandbyEquip(player, "camel") and ld.Equipinvoked(player, "camel") then
      return player.phase == Player.Discard
    end
  end,
  on_refresh = function(self, event, target, player, data)
    player.room:addPlayerMark(player, "AddMaxCards-turn", 2)
  end,
}

local camel = fk.CreateOffensiveRide{
  name = "camel",
  suit = Card.Club,
  number = 5,
}

Fk:addSkill(camel_trigger)
extension:addCard(camel)
ld.addCardToStandby(camel)

Fk:loadTranslationTable{
  ["camel"] = "骆驼",
  ["#camel_skill"] = "骆驼",
  [":camel"] = "<font color=\"#009E60\"><b>装备牌·备用/坐骑</b></font><br /><b>技能</b>：你使用【粮】不消耗指令，你的手牌上限+2。",
}

local nightmare_damage = fk.CreateTriggerSkill{
  name = "#nightmare_damage",
  frequency = Skill.Compulsory,
  anim_type = "masochism",
  events = {fk.Damaged},
  can_trigger = function(self, event, target, player, data)
    if target == player and data.from and data.from ~= player and (player:hasSkill("#nightmare_skill") or ld.hasStandbyEquip(player, "nightmare"))
     and ld.Equipinvoked(player, "nightmare") then
      return #player.room.logic:getEventsOfScope(GameEvent.ChangeHp, 999, function (e)
        local damage = e.data[5]
        if damage and damage.from and player:getNextAlive() == damage.from and player == damage.to then
          return true
        end
      end, Player.HistoryTurn) == 1
     end
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    ld.addinstruction(data.from, -1)
  end,
}

local nightmare_skill = fk.CreateTriggerSkill{
  name = "#nightmare_skill",
  attached_equip = "nightmare",
}

local nightmare = fk.CreateOffensiveRide{
  name = "nightmare",
  suit = Card.Club,
  number = 6,
  equip_skill = nightmare_skill,
}

Fk:addSkill(nightmare_skill)
Fk:addSkill(nightmare_damage)
extension:addCard(nightmare)

Fk:loadTranslationTable{
  ["nightmare"] = "梦魇",
  ["#nightmare_skill"] = "梦魇",
  ["#nightmare_damage"] = "梦魇",
  [":nightmare"] = "<font color=\"#009E60\"><b>装备牌/坐骑</b></font><br /><b>技能</b>：当对手每回合首次对你造成伤害后，其指令-1。",
}

local ride_spear_skill = fk.CreateTriggerSkill{
  name = "#ride_spear",
  frequency = Skill.Compulsory,
  attached_equip = "ride_spear",
  events = {fk.CardUseFinished},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self.name) and TargetGroup:getRealTargets(data.tos)[1] == player.id and data.card.name == "br__slash" and
    ld.Equipinvoked(player, "ride_spear") and not player:isKongcheng() 
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if player:getMark("instruction") > 0 or player:getMark("free_instruction") > 0 or
    (player:getEquipment(Card.SubtypeOffensiveRide) or #player:getPile("sixdragon") > 0 or ld.hasStandbyEquip(player, "camel")) then
      local card = room:askForCard(player, 1, 1, false, self.name, true, ".|.|.|hand", "#ride_spear_use")
      if #card > 0 then
        --U.askForUseVirtualCard(room, player, "br__slash", card, self.name, "#ride_spear_slash")
        if player:getEquipment(Card.SubtypeOffensiveRide) or #player:getPile("sixdragon") > 0 or ld.hasStandbyEquip(player, "camel") then
          room:addPlayerMark(player, "free_instruction")
        end
        room:useVirtualCard("br__slash", card, player, player:getNextAlive(), self.name, true)
      end
    end
  end,
}

local ride_spear = fk.CreateWeapon{
  name = "ride_spear",
  suit = Card.Club,
  number = 7,
  equip_skill = ride_spear_skill,
}

Fk:addSkill(ride_spear_skill)
extension:addCard(ride_spear)
  
Fk:loadTranslationTable{
  ["ride_spear"] = "骑枪",
  ["#ride_spear"] = "骑枪",
  [":ride_spear"] = "<font color=\"#009E60\"><b>装备牌/武器</b></font><br /><b>武器技能</b>：对手对你使用【杀】结算后：你可将一张手牌当【杀】使用（若你装备区有坐骑牌则不消耗指令）。",
  ["#ride_spear_use"] = "骑枪：你可以将一张手牌当【杀】使用",
  ["#ride_spear_slash"] = "骑枪：请选择【杀】的目标",
}

local jinglan_skill = fk.CreateViewAsSkill{
  name = "jinglan_skill&",
  attached_equip = "jinglan",
  pattern = "shot__slash",
  card_filter = function(self, to_select, selected)
    return #selected == 0 and Fk:getCardById(to_select).name == "br__jink"
  end,
  view_as = function(self, cards)
    if #cards ~= 1 then
      return nil
    end
    local c = Fk:cloneCard("shot__slash")
    c.skillName = self.name
    c:addSubcard(cards[1])
    return c
  end,
  before_use = function(self, player, use)
    if use.card.skillName == self.name then
      player.room:addPlayerMark(player, "free_instruction")
    end
  end,
  enabled_at_play = function (self, player)
    return ld.Equipinvoked(player, "jinglan")
  end,
  enabled_at_response = function (self, player)
    return ld.Equipinvoked(player, "jinglan")
  end,
}

local jinglan = fk.CreateWeapon{
  name = "jinglan",
  suit = Card.Club,
  number = 8,
  equip_skill = jinglan_skill,
}

Fk:addSkill(jinglan_skill)
extension:addCard(jinglan)
  
Fk:loadTranslationTable{
  ["jinglan"] = "井阑",
  ["jinglan_skill&"] = "井阑",
  [":jinglan"] = "<font color=\"#009E60\"><b>装备牌/武器</b></font><br /><b>武器技能</b>：你可将【防】当不消耗指令的【射】使用。",
}

local boomerang_skill = fk.CreateViewAsSkill{
  name = "boomerang_skill&",
  --attached_equip = "boomerang",
  pattern = "shot__slash",
  expand_pile = "#standby",
  card_filter = function(self, to_select, selected)
    return #selected == 0 and Self:getPileNameOfId(to_select) == "#standby" and Fk:getCardById(to_select).name == "boomerang"
  end,
  view_as = function(self, cards)
    if #cards ~= 1 then
      return nil
    end
    local c = Fk:cloneCard("shot__slash")
    c.skillName = self.name
    c:addSubcard(cards[1])
    return c
  end,
}

local boomerang_slash = fk.CreateTriggerSkill{
  name = "#boomerang_slash",
  anim_type = "offensive",
  mute = true,
  priority = 4,
  events = {fk.CardUseFinished},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self.name) and data.card.name == "shot__slash" and
    data.card.skillName == "boomerang_skill&" and player.room:getCardArea(data.card) == Card.Processing and not data.damageDealt
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:moveCardTo(data.card, Card.PlayerHand, player, fk.ReasonJustMove, self.name, "", true)
  end,
}

local Boomerang = fk.CreateWeapon{
  name = "boomerang",
  suit = Card.Club,
  number = 9,
}

Fk:addSkill(boomerang_skill)
Fk:addSkill(boomerang_slash)
extension:addCard(Boomerang)
ld.addCardToStandby(Boomerang)

Fk:loadTranslationTable{
  ["boomerang"] = "回旋镖",
  ["boomerang_skill&"] = "回旋镖",
  ["#boomerang_slash"] = "回旋镖",
  [":boomerang"] = "<font color=\"#009E60\"><b>装备牌·备用/武器</b></font><br /><b>武器技能</b>：此牌可以当不消耗指令的【射】使用，结算后若未造成伤害，则你获得此牌。",
  [":boomerang_skill&"] = "此牌可以当不消耗指令的【射】使用，结算后若未造成伤害，则你获得此牌。",
}

local br__qinggang_skill = fk.CreateTriggerSkill{
  name = "#br__qinggang",
  frequency = Skill.Compulsory,
  attached_equip = "br__qinggang",
  events = {fk.DrawNCards},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self.name) and ld.Equipinvoked(player, "br__qinggang")
    and #table.filter(player:getNextAlive():getPile("#standby"), function(id) return Fk:getCardById(id).sub_type == Card.SubtypeArmor end) == 0
    and not player:getNextAlive():getEquipment(Card.SubtypeArmor)
  end,
  on_use = function(self, event, target, player, data)
    player.room:setEmotion(player, "./packages/standard_cards/image/anim/qinggang_sword")
    data.n = data.n + 1
  end,
}

local br__qinggang = fk.CreateWeapon{
  name = "br__qinggang",
  suit = Card.Club,
  number = 10,
  equip_skill = br__qinggang_skill,
  on_install = function(self, room, player)
    room:handleAddLoseSkills(player, "#br__qinggang", nil, false, true)
    if ld.Equipinvoked(player, self.name) then
      room:setPlayerMark(player:getNextAlive(), "@@armor_invalid", 1)
    end
  end,
  on_uninstall = function(self, room, player)
    room:handleAddLoseSkills(player, "-#br__qinggang", nil, false, true)
    room:setPlayerMark(player:getNextAlive(), "@@armor_invalid", 0)
  end,
}

Fk:addSkill(br__qinggang_skill)
extension:addCard(br__qinggang)

Fk:loadTranslationTable{
  ["br__qinggang"] = "青釭剑",
  ["#br__qinggang"] = "青釭剑",
  ["@@armor_invalid"] = "<font color=\"#B2BEB5\">防具无效</font>",
  [":br__qinggang"] = "<font color=\"#009E60\"><b>装备牌/武器</b></font><br /><b>武器技能</b>：对手的防具牌无效。<br />若对手装备区没有防具牌，摸牌阶段你额外摸一张牌。",
}

local iron_tribulus_skill = fk.CreateTriggerSkill{
  name = "#iron_tribulus",
  anim_type = "masochism",
  events = {fk.Damaged},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self.name) and ld.hasStandbyEquip(player, "iron_tribulus")
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local to = data.from
    if ld.hasStandbyEquip(player, "iron_tribulus") then
      local id = table.filter(player:getPile("#standby"), function(id) return Fk:getCardById(id).name == "iron_tribulus" end)
      room:moveCardTo(id, Card.DiscardPile, nil, fk.ReasonDiscard, self.name)
    end
    local id = -1
    local horses = table.simpleClone(table.filter(to:getCardIds("he"), function(id)
      return Fk:getCardById(id).sub_type == Card.SubtypeOffensiveRide or Fk:getCardById(id).sub_type == Card.SubtypeDefensiveRide end))
    table.insertTable(horses, table.simpleClone(table.filter(to:getPile("#standby"), function(id)
      return Fk:getCardById(id).sub_type == Card.SubtypeOffensiveRide or Fk:getCardById(id).sub_type == Card.SubtypeDefensiveRide end)))
      table.insertTable(horses, table.simpleClone(table.filter(to:getPile("sixdragon"), function(id)
        return Fk:getCardById(id).sub_type == Card.SubtypeOffensiveRide or Fk:getCardById(id).sub_type == Card.SubtypeDefensiveRide end)))
    if #horses > 0 then
      id = player.room:askForCardChosen(to, to, {
        card_data = {
          {"horses", horses},
        }
      }, self.name)
      if id ~= -1 then
        room:moveCardTo(id, Card.DiscardPile, nil, fk.ReasonDiscard, self.name, "", true)
      end
    end
    if id == -1 then
      room:damage({
        from = player,
        to = to,
        damage = 1,
        damageType = fk.NormalDamage,
        skillName = self.name,
      })
    end
  end,
  --can_refresh
}

local iron_tribulus = fk.CreateWeapon{
  name = "iron_tribulus",
  suit = Card.Club,
  number = 11,
}
  
Fk:addSkill(iron_tribulus_skill)
extension:addCard(iron_tribulus)
ld.addCardToStandby(iron_tribulus)

Fk:loadTranslationTable{
  ["iron_tribulus"] = "铁蒺藜",
  ["#iron_tribulus"] = "铁蒺藜",
  [":iron_tribulus"] = "<font color=\"#009E60\"><b>装备牌·备用/武器</b></font><br /><b>武器技能</b>：对手使用【杀】对你造成伤害后：你弃置此牌，然后其须弃置一张坐骑牌，否则你对其造成1点伤害。",
}

local light_bow_skill = fk.CreateTriggerSkill{
  name = "#light_bow",
  attached_equip = "light_bow",
  frequency = Skill.Compulsory,
  refresh_events = {fk.PreCardUse},
  can_refresh = function(self, event, target, player, data)
    return target == player and player:hasSkill(self.name) and data.card.name == "shot__slash" and ld.Equipinvoked(player, "light_bow")
  end,
  on_refresh = function(self, event, target, player, data)
    --player.room:addPlayerMark(player, "free_instruction")
    ld.addinstruction(player, 1)
  end,
}

local light_bow = fk.CreateWeapon{
  name = "light_bow",
  suit = Card.Club,
  number = 12,
  equip_skill = light_bow_skill,
}

Fk:addSkill(light_bow_skill)
extension:addCard(light_bow)
  
Fk:loadTranslationTable{
  ["light_bow"] = "轻弓",
  ["#light_bow"] = "轻弓",
  [":light_bow"] = "<font color=\"#009E60\"><b>装备牌/武器</b></font><br /><b>武器技能</b>：你使用【射】不消耗指令。",
}

local waterwheel_skill = fk.CreateTriggerSkill{
  name = "#waterwheel_skill",
  anim_type = "drawcard",
  events = {fk.CardUsing},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and player.phase ~= Player.NotActive and self.cost_data
    and player:usedSkillTimes(self.name) < 3
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    player:drawCards(1, self.name)
  end,

  refresh_events = {fk.AfterCardUseDeclared},
  can_refresh = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and player.phase ~= Player.NotActive
  end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    self.cost_data = false
    if data.card.suit == Card.NoSuit then
      room:setPlayerMark(player, "@waterwheel-turn", 0)
      room:setPlayerMark(player, "waterwheel_suit-turn", 0)
      self.cost_data = false
    else
      if data.card:getSuitString() == player:getMark("waterwheel_suit-turn") then
        self.cost_data = true
      else
        self.cost_data = false
      end
      room:setPlayerMark(player, "@waterwheel-turn", data.card:getSuitString(true))
      room:setPlayerMark(player, "waterwheel_suit-turn", data.card:getSuitString())
    end
  end,
}

local waterwheel = fk.CreateTreasure{
  name = "waterwheel",
  suit = Card.Club,
  number = 13,
  equip_skill = waterwheel_skill,
  on_install = function(self, room, player)
    room:handleAddLoseSkills(player, "#waterwheel_skill", nil, false, true)
    room:setPlayerMark(player, "@waterwheel-turn", "♣")
    room:setPlayerMark(player, "waterwheel_suit-turn", "club")
  end,
  on_uninstall = function(self, room, player)
    room:handleAddLoseSkills(player, "-#waterwheel_skill", nil, false, true)
    room:setPlayerMark(player, "@waterwheel-turn", 0)
    room:setPlayerMark(player, "waterwheel_suit-turn", 0)
  end,
}

Fk:addSkill(waterwheel_skill)
extension:addCard(waterwheel)

Fk:loadTranslationTable{
  ["waterwheel"] = "龙骨水车",
  ["#waterwheel_skill"] = "龙骨水车",
  [":waterwheel"] = "<font color=\"#009E60\"><b>装备牌/宝物</b></font><br /><b>宝物技能</b>：你的回合内，当你使用牌后，若与你本回合使用的上一张牌花色相同，你摸一张牌。（每回合限三次）",
  ["@waterwheel-turn"] = "龙骨水车",
}

local jadeseal_skill = fk.CreateActiveSkill{
  name = "jadeseal_skill&",
  prompt = "你可以获得1点指令",
  attached_equip = "br__jadeseal",
  target_num = 0,
  card_num = 0,
  card_filter = Util.FalseFunc,
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryPhase) == 0 and not ld.hasPolicyorTrap(player, "eightdiagrams")
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    room:notifySkillInvoked(player, "br__jadeseal", "special")
    ld.addinstruction(player, 1)
  end,
}

local jadeseal = fk.CreateTreasure{
  name = "br__jadeseal",
  suit = Card.Diamond,
  number = 1,
  equip_skill = jadeseal_skill,
}

Fk:addSkill(jadeseal_skill)
extension:addCard(jadeseal)

Fk:loadTranslationTable{
  ["br__jadeseal"] = "玉玺",
  ["jadeseal_skill&"] = "玉玺",
  [":jadeseal_skill&"] = "出牌阶段限一次，你可以加1点指令。",
  [":br__jadeseal"] = "<font color=\"#009E60\"><b>装备牌/宝物</b></font><br /><b>宝物技能</b>：出牌阶段限一次，你可以加1点指令。",
}

local squareshield_skill = fk.CreateTriggerSkill{
  name = "#squareshield_skill",
  attached_equip = "squareshield",
}

local squareshield = fk.CreateArmor{
  name = "squareshield",
  suit = Card.Diamond,
  number = 2,
  equip_skill = squareshield_skill,
}

Fk:addSkill(squareshield_skill)
extension:addCard(squareshield)

Fk:loadTranslationTable{
  ["squareshield"] = "方盾",
  ["#squareshield_skill"] = "方盾",
  [":squareshield"] = "<font color=\"#009E60\"><b>装备牌/防具</b></font><br /><b>防具技能</b>：你使用【防】不消耗指令。",
}

local demolisher_skill = fk.CreateTriggerSkill{
  name = "#demolisher",
  --anim_type = "offensive",
  mute = true,
  events = {fk.AfterCardsMove},
  can_trigger = function(self, event, target, player, data)
    if not ld.Equipinvoked(player, "demolisher") then return false end
    for _, move in ipairs(data) do
      if move.from and move.from == player.id and move.proposer and move.from ~= move.proposer then
        for _, info in ipairs(move.moveInfo) do
          local id = info.cardId
          if info.fromArea == Card.PlayerEquip and Fk:getCardById(id).sub_type == Card.SubtypeArmor then
            return (move.moveReason == fk.ReasonDiscard or move.moveReason == fk.ReasonPrey) and ld.hasStandbyEquip(player, "demolisher")
          elseif info.fromArea == Card.PlayerSpecial and Fk:getCardById(id).name == "demolisher" then
            return move.moveReason == fk.ReasonDiscard or move.moveReason == fk.ReasonPrey
          end
        end
      end
    end
  end,
  on_cost = Util.TrueFunc,
  on_trigger = function(self, event, target, player, data)
    for _, move in ipairs(data) do
      if move.from and move.from == player.id then
        for _, info in ipairs(move.moveInfo) do
          local id = info.cardId
          if info.fromArea == Card.PlayerEquip and Fk:getCardById(id).sub_type == Card.SubtypeArmor then
            player:drawCards(2, "demolisher")
          elseif info.fromArea == Card.PlayerSpecial and Fk:getCardById(id).name == "demolisher" then
            player.room:damage({
              from = player,
              to = player:getNextAlive(),
              damage = 1,
              damageType = fk.NormalDamage,
              skillName = self.name,
            })
          end
        end
      end
    end
  end,
}

local demolisher = fk.CreateArmor{
  name = "demolisher",
  suit = Card.Diamond,
  number = 3,
}
  
Fk:addSkill(demolisher_skill)
extension:addCard(demolisher)
ld.addCardToStandby(demolisher)
  
Fk:loadTranslationTable{
  ["demolisher"] = "塞门刀车",
  ["#demolisher"] = "塞门刀车",
  [":demolisher"] = "<font color=\"#009E60\"><b>装备牌·备用/防具</b></font><br /><b>防具技能</b>：当你防具栏的防具牌被对手弃置或获得后，你摸两张牌。当此牌被对手弃置或获得后，你对其造成1点伤害。",
}

local vine_skill = fk.CreateTriggerSkill{
  name = "#br__vine",
  frequency = Skill.Compulsory,
  attached_equip = "br__vine",
  events = {fk.DamageInflicted},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self.name) and ld.Equipinvoked(player, "br__vine") and
    data.card and (data.card.trueName == "slash" or data.card.trueName == "savage_assault" or data.card.trueName == "archery_attack" or
    data.card.trueName == "fire_attack" or data.card.trueName == "desperado")
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    if data.card.trueName == "slash" or data.card.trueName == "savage_assault" or data.card.trueName == "archery_attack" then
      player.room:broadcastPlaySound("./packages/maneuvering/audio/card/vine")
      player.room:setEmotion(player, "./packages/maneuvering/image/anim/vine")
      local num = player:getMark("vine_buff") - 1
      if num > 0 then
        player.room:setPlayerMark(player, "vine_buff", num)
        player.room:setPlayerMark(player, "@vine_buff", num.."/2")
      else
        local armor = player:getEquipment(Card.SubtypeArmor)
        player.room:moveCardTo(armor, Card.DiscardPile, nil, fk.ReasonJustMove, self.name)
      end
      return true
    elseif data.card.trueName == "fire_attack" or data.card.trueName == "desperado" then
      player.room:broadcastPlaySound("./packages/maneuvering/audio/card/vineburn")
      player.room:setEmotion(player, "./packages/maneuvering/image/anim/vineburn")
      data.damage = data.damage + 1
    end
  end,
}

local vine = fk.CreateArmor{
  name = "br__vine",
  suit = Card.Diamond,
  number = 4,
  equip_skill = vine_skill,
  on_install = function(self, room, player)
    room:handleAddLoseSkills(player, "#br__vine", nil, false, true)
    room:setPlayerMark(player, "vine_buff", 2)
    room:setPlayerMark(player, "@vine_buff", "2/2")
  end,
  on_uninstall = function(self, room, player)
    room:handleAddLoseSkills(player, "-#br__vine", nil, false, true)
    room:setPlayerMark(player, "vine_buff", 0)
    room:setPlayerMark(player, "@vine_buff", 0)
  end,
}
  
Fk:addSkill(vine_skill)
extension:addCard(vine)
  
Fk:loadTranslationTable{
  ["br__vine"] = "藤甲",
  ["#br__vine"] = "藤甲",
  ["@vine_buff"] = "藤甲耐久",
  [":br__vine"] = "<font color=\"#009E60\"><b>装备牌/防具</b></font><br /><b>防具技能</b>：防止【杀】和【射】、【箭雨】和【象阵】对你造成伤害，然后若已累计防止两次，则你弃置此牌。<br />"..
"【火攻】和【死士】对你造成伤害+1。",
}

local poster_draw = fk.CreateTriggerSkill{
  name = "#poster_draw",
  priority = 4,
  frequency = Skill.Compulsory,
  events = {fk.TurnEnd},
  can_trigger = function(self, event, target, player, data)
    return target == player and (player:hasSkill("#poster_skill") or ld.hasStandbyEquip(player, "poster")) and ld.Equipinvoked(player, "poster")
  end,
  on_use = function(self, event, target, player, data)
    player:drawCards(1, "poster")
  end,
}

local poster_skill = fk.CreateTriggerSkill{
  name = "#poster_skill",
  attached_equip = "poster",
}

local poster = fk.CreateOffensiveRide{
  name = "poster",
  suit = Card.Diamond,
  number = 5,
  equip_skill = poster_skill,
}

Fk:addSkill(poster_skill)
Fk:addSkill(poster_draw)
extension:addCard(poster)

Fk:loadTranslationTable{
  ["poster"] = "驿马",
  ["#poster_skill"] = "驿马",
  ["#poster_draw"] = "驿马",
  [":poster"] = "<font color=\"#009E60\"><b>装备牌/坐骑</b></font><br /><b>技能</b>：回合结束时，你摸一张牌。",
}

local goodhorse_recover = fk.CreateTriggerSkill{
  name = "#goodhorse_recover",
  events = {fk.HpChanged},
  can_trigger = function(self, event, target, player, data)
    return target == player and (player:hasSkill("#goodhorse_skill") or ld.hasStandbyEquip(player, "goodhorse")) and
    player.hp <= 0 and ld.Equipinvoked(player, "goodhorse")
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    local card
    if player:getEquipment(Card.SubtypeOffensiveRide) and Fk:getCardById(player:getEquipment(Card.SubtypeOffensiveRide)).name == "goodhorse" then
      card = player:getEquipment(Card.SubtypeOffensiveRide)
    elseif #table.filter(player:getPile("sixdragon"), function(id) return Fk:getCardById(id).name == "goodhorse" end) > 0 then
      card = table.filter(player:getPile("sixdragon"), function(id) return Fk:getCardById(id).name == "goodhorse" end)[1]
    end
    if card ~= -1 then
      player.room:moveCardTo(card, Card.DiscardPile, nil, fk.ReasonDiscard, self.name)
      player.room:recover({
        who = player,
        num = 2,
        recoverBy = player,
        skillName = self.name
      })
    end
  end,
}

local goodhorse_skill = fk.CreateTriggerSkill{
  name = "#goodhorse_skill",
  attached_equip = "goodhorse",
}

local goodhorse = fk.CreateOffensiveRide{
  name = "goodhorse",
  suit = Card.Diamond,
  number = 6,
  equip_skill = goodhorse_skill,
}

Fk:addSkill(goodhorse_skill)
Fk:addSkill(goodhorse_recover)
extension:addCard(goodhorse)
  
Fk:loadTranslationTable{
  ["goodhorse"] = "良驹",
  ["#goodhorse_skill"] = "良驹",
  ["#goodhorse_recover"] = "良驹",
  [":goodhorse"] = "<font color=\"#009E60\"><b>装备牌/坐骑</b></font><br /><b>技能</b>：当你国力减至不大于0时，你弃置此牌并恢复2点国力。",
}

local yanyueblade_skill = fk.CreateTriggerSkill{
  name = "#yanyueblade_skill",
  attached_equip = "yanyueblade",
  frequency = Skill.Compulsory,
  events = {fk.TargetSpecified},
  can_trigger = function(self, event, target, player, data)
    return data.card and data.card.name == "br__slash" and target == player and player:hasSkill(self.name) and
    ld.Equipinvoked(player, "yanyueblade") and player:getMark("yanyueblade") > 0
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    player.room:removePlayerMark(player, "yanyueblade")
    player.room:setEmotion(player, "./packages/standard_cards/image/anim/blade")
    player.room:notifySkillInvoked(player, self.name)
    player.room:setPlayerMark(player, "@yanyueblade", player:getMark("yanyueblade").."/2")
    data.disresponsive = true
  end,
}

local yanyueblade = fk.CreateWeapon{
  name = "yanyueblade",
  suit = Card.Diamond,
  number = 7,
  equip_skill = yanyueblade_skill,
  on_install = function(self, room, player)
    room:handleAddLoseSkills(player, "#yanyueblade_skill", nil, false, true)
    room:setPlayerMark(player, "yanyueblade", 2)
    room:setPlayerMark(player, "@yanyueblade", "2/2")
  end,
  on_uninstall = function(self, room, player)
    room:handleAddLoseSkills(player, "-#yanyueblade_skill", nil, false, true)
    room:setPlayerMark(player, "yanyueblade", 0)
    room:setPlayerMark(player, "@yanyueblade", 0)
  end,
}

Fk:addSkill(yanyueblade_skill)
extension:addCard(yanyueblade)
  
Fk:loadTranslationTable{
  ["yanyueblade"] = "偃月刀",
  ["#yanyueblade_skill"] = "偃月刀",
  [":yanyueblade"] = "<font color=\"#009E60\"><b>装备牌/武器</b></font><br /><b>武器技能</b>：你装备此牌后前两次使用【杀】无法抵消。",
  ["@yanyueblade"] = "偃月耐久",
}

local helepolis_skill = fk.CreateTriggerSkill{
  name = "#helepolis",
  attached_equip = "helepolis",
  events = {fk.TargetSpecified},
  can_trigger = function(self, event, target, player, data)
    if target == player and player:hasSkill(self.name) and data.tos and data.firstTarget and data.card.name == "br__slash" then
      local to = player.room:getPlayerById(data.to)
      return to:getEquipment(Card.SubtypeArmor) or #table.filter(to:getPile("#standby"), function(id) return Fk:getCardById(id).sub_type == Card.SubtypeArmor end) > 0
    end
  end,
  on_use = function(self, event, target, player, data)
    local to = player.room:getPlayerById(data.to)
    local cards = to:getCardIds(Player.Hand)
    if not to:isKongcheng() then
      cards = {}
      for i = 1, #to:getCardIds(Player.Hand), 1 do
        table.insert(cards, -1)
      end
    end
    local to_discard = {}
    if #cards ~= 0 then table.insertIfNeed(to_discard, {"$Hand", cards}) end
    if to:getEquipment(Card.SubtypeArmor) then table.insertIfNeed(to_discard, {"$Equip", {to:getEquipment(Card.SubtypeArmor)}}) end
    if #table.filter(to:getPile("#standby"), function(cid) return Fk:getCardById(cid).sub_type == Card.SubtypeArmor end) > 0 then
      table.insertIfNeed(to_discard, {"#standby", table.filter(to:getPile("#standby"), function(cid) return Fk:getCardById(cid).sub_type == Card.SubtypeArmor end)})
    end
    if #to_discard == 0 then return nil end
    local id = player.room:askForCardChosen(player, to, {card_data = to_discard}, self.name)
    if id ~= -1 then
      player.room:moveCardTo(id, Card.DiscardPile, nil, fk.ReasonDiscard, self.name, "", true, player.id)
    end
  end,
}

local helepolis = fk.CreateWeapon{
  name = "helepolis",
  suit = Card.Diamond,
  number = 8,
  equip_skill = helepolis_skill,
}

Fk:addSkill(helepolis_skill)
extension:addCard(helepolis)
  
Fk:loadTranslationTable{
  ["helepolis"] = "冲车",
  ["#helepolis"] = "冲车",
  [":helepolis"] = "<font color=\"#009E60\"><b>装备牌/武器</b></font><br /><b>武器技能</b>：当你使用【杀】指定目标后，若其装备区有防具牌，你可弃置其一张手牌或防具牌。",
}

local nine_segmented_skill = fk.CreateViewAsSkill{
  name = "nine_segmented_skill&",
  attached_equip = "nine_segmented",
  pattern = ".|.|.|.|.|br__slash,br__jink",
  interaction = function() 
    local names = {"br__slash", "br__jink"}
    return UI.ComboBox {choices = names}
  end,

  card_filter = function(self, to_select, selected)
    return #selected == 0 and Fk:getCardById(to_select).type == Card.TypeBasic and Fk:getCardById(to_select).number <= 9
  end,
  view_as = function(self, cards)
    if #cards ~= 1 or not self.interaction.data then return end
    local card = Fk:cloneCard(self.interaction.data)
    card.skillName = self.name
    card:addSubcards(cards)
    return card
  end,
  before_use = function(self, player, use)
    if use.card.skillName == self.name and use.card.number == 9 then
      player.room:addPlayerMark(player, "free_instruction")
    end
  end,
  enabled_at_play = function (self, player)
    return ld.Equipinvoked(player, "nine_segmented")
  end,
  enabled_at_response = function (self, player)
    return ld.Equipinvoked(player, "nine_segmented")
  end,
}

local nine_segmented = fk.CreateWeapon{
  name = "nine_segmented",
  suit = Card.Diamond,
  number = 9,
  equip_skill = nine_segmented_skill,
}

Fk:addSkill(nine_segmented_skill)
extension:addCard(nine_segmented)
  
Fk:loadTranslationTable{
  ["nine_segmented"] = "九节棍",
  ["nine_segmented_skill&"] = "九节棍",
  [":nine_segmented"] = "<font color=\"#009E60\"><b>装备牌/武器</b></font><br /><b>武器技能</b>：你可将点数不大于9的指令牌当【杀】或【防】使用，若点数为9则不消耗指令。",
}

local whip_skill = fk.CreateTriggerSkill{
  name = "#whip",
  attached_equip = "whip",
  events = {fk.DamageCaused},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self.name) and ld.Equipinvoked(player, "whip") and
    data.card and data.card.name == "br__slash"
  end,
  on_cost = function(self, event, target, player, data)
    local card = player.room:askForCard(player, 1, 1, false, self.name, true, ".", "#whip_throw")
    if #card > 0 then
      self.cost_data = card[1]
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    player.room:moveCardTo(self.cost_data, Card.DiscardPile, nil, fk.ReasonDiscard, self.name)
    local suit = Fk:getCardById(self.cost_data):getSuitString()
    local cards = player.room:askForDiscard(data.to, 1, 1, true, self.name, true,  ".|.|" .. suit , "#whip-throw")
    if #cards > 0 then
      player.room:moveCardTo(cards[1], Card.DiscardPile, nil, fk.ReasonDiscard, self.name)
    else
      data.damage = data.damage + 1
    end
  end,
}

local whip = fk.CreateWeapon{
  name = "whip",
  suit = Card.Diamond,
  number = 10,
  equip_skill = whip_skill,
}

  
Fk:addSkill(whip_skill)
extension:addCard(whip)
  
Fk:loadTranslationTable{
  ["whip"] = "刑鞭",
  ["#whip"] = "刑鞭",
  [":whip"] = "<font color=\"#009E60\"><b>装备牌/武器</b></font><br /><b>武器技能</b>：当你使用【杀】造成伤害时，你可弃置一张手牌，则对方须弃置一张与之花色相同的牌，否则伤害+1。",
  ["#whip_throw"] = "刑鞭：你可弃置一张手牌",
  ["#whip-throw"] = "刑鞭：请弃置一张花色相同的牌，否则伤害+1",
}

local plunderblade_skill = fk.CreateTriggerSkill{
  name = "#plunderblade",
  attached_equip = "plunderblade",
  events = {fk.Damage},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self.name) and ld.Equipinvoked(player, "plunderblade") and
    data.card and data.card.name == "br__slash"
  end,
  on_use = function(self, event, target, player, data)
    local to = data.to
    local room = player.room
    local cards = to:getCardIds(Player.Hand)
    if not to:isKongcheng() then
      cards = {}
      for i = 1, #to:getCardIds(Player.Hand), 1 do
        table.insert(cards, -1)
      end
    end
    local to_discard = {}
    if #cards ~= 0 then table.insertIfNeed(to_discard, {"$Hand", cards}) end
    if #to:getCardIds(Player.Equip) ~= 0 then table.insertIfNeed(to_discard, {"$Equip", to:getCardIds(Player.Equip)}) end
    if #to:getPile("#standby") > 0 then table.insertIfNeed(to_discard, {"#standby", to:getPile("#standby")}) end
    if #to:getPile("sixdragon") > 0 then table.insertIfNeed(to_discard, {"sixdragon", to:getPile("sixdragon")}) end
    if #to_discard == 0 then return nil end
    local id = room:askForCardChosen(player, to, {card_data = to_discard}, self.name)
    if id ~= -1 then
      if room:getCardArea(id) ~= Card.PlayerHand then
        room:moveCardTo(player:getEquipment(Card.SubtypeWeapon), Card.DiscardPile, nil, fk.ReasonDiscard, self.name, "", true, player.id)
      end
      room:moveCardTo(id, Card.PlayerHand, player, fk.ReasonPrey, self.name, "", true, player.id)
    end
  end,
}

local plunderblade = fk.CreateWeapon{
  name = "plunderblade",
  suit = Card.Diamond,
  number = 11,
  equip_skill = plunderblade_skill,
}

Fk:addSkill(plunderblade_skill)
extension:addCard(plunderblade)
  
Fk:loadTranslationTable{
  ["plunderblade"] = "掠夺弯刀",
  ["#plunderblade"] = "掠夺弯刀",
  [":plunderblade"] = "<font color=\"#009E60\"><b>装备牌/武器</b></font><br /><b>武器技能</b>：当你使用【杀】造成伤害后，你可获得目标一张手牌，或弃置此牌然后获得其装备区的一张牌。",
}

local peacebook_skill = fk.CreateTriggerSkill{
  name = "#peacebook_skill",
  attached_equip = "peace_book",
  events = {fk.TurnStart},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self.name) and not ld.hasPolicyorTrap(player, "eightdiagrams")
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local judge = {
      who = player,
      reason = "peace_book",
      pattern = ".|.|heart,spade",
    }
    player.room:judge(judge)
    local result = judge.card
    if result.suit == Card.Spade then
      room:damage({
        from = player,
        to = player:getNextAlive(),
        damage = 1,
        damageType = fk.ThunderDamage,
        skillName = self.name
      })
    elseif result.suit == Card.Heart then
      room:recover({
        who = player,
        num = 1,
        recoverBy = player,
        skillName = self.name
      })
    end
  end,
}

local peacebook = fk.CreateTreasure{
  name = "peace_book",
  suit = Card.Diamond,
  number = 12,
  equip_skill = peacebook_skill,
}

Fk:addSkill(peacebook_skill)
extension:addCard(peacebook)

Fk:loadTranslationTable{
  ["peace_book"] = "太平要术",
  ["#peacebook_skill"] = "太平要术",
  [":peace_book"] = "<font color=\"#009E60\"><b>装备牌/宝物</b></font><br /><b>宝物技能</b>：回合开始时，你可进行一次判定，若为<font color=\"#FF4433\">红桃</font>，你回复1点国力，若为<b>黑桃</b>，你对对手造成1点伤害。",
}

local armillary_skill = fk.CreateTriggerSkill{
  name = "#armillary_skill",
  anim_type = "control",
  events = {fk.AskForRetrial},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) and ld.hasStandbyEquip(player, "armillary") and not player:isNude()
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local prompt = "#armillary-ask::" .. target.id
    local card = room:askForResponse(player, self.name, ".", prompt, true)
    if card ~= nil then
      self.cost_data = card
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    player.room:retrial(self.cost_data, player, data, self.name)
  end,
}

local armillary = fk.CreateTreasure{
  name = "armillary",
  suit = Card.Diamond,
  number = 13,
}

Fk:addSkill(armillary_skill)
extension:addCard(armillary)
ld.addCardToStandby(armillary)

Fk:loadTranslationTable{
    ["armillary"] = "浑天仪",
    ["#armillary_skill"] = "浑天仪",
    [":armillary"] = "<font color=\"#009E60\"><b>装备牌·备用/宝物</b></font><br /><b>宝物技能</b>：每回合限一次，你或对手的判定牌生效前，你可用一张牌代替之。",
    ["#armillary-ask"] = "浑天仪：你可用一张牌代替%dest的判定牌",
}

return extension